package net.jueb.marshalling.server;

import net.jueb.marshalling.pojo.Request;
import net.jueb.marshalling.pojo.Response;
import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;

public class MarshallingServerHandler extends ChannelHandlerAdapter{
	private int count;
	
	@Override
	public void channelRead(ChannelHandlerContext ctx, Object msg)
			throws Exception {
		Request request=(Request)msg;
		if(request==null)
		{
			return ;
		}
		count++;
		System.out.println("收到请求:"+request);
		
		Response response=new Response();
		response.setId(count);
		response.setResult("Hello Client！");
		ctx.writeAndFlush(response);
		
	}
	@Override
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
			throws Exception {
		cause.printStackTrace();
		ctx.close();
	}
}
